<script>
	export default {
		globalData: {
			appid: '',
			apiUri: "https://fitness.xiegaosheng.com/api",
			imageUri: "https://fitness.xiegaosheng.com",
			safeAreaBottom: 0,

			event: {
				userUpdate: "userUpdate",
				shopChange: "shopChange",
				cityChange: 'currentCityChange'
			},
			currentCity: {
				id: 104,
				name: '上海',
			},
			shareConfig: {
				shareTitle: "邀请好友得佣金，赶紧行动吧～",
				shareImage: ''
			},
			config: {
				course_templates: [],
				activity_templates: []
			}
		},
		onLaunch: function() {
			let app = this;
			app.$core.onRequestComplete(function(ret, response) {
				if (ret && ret.code === 401) {
					if (app.$core.getUserinfo()) {
						app.$core.logout();
						uni.navigateTo({
							url: '/pages/user/login/login'
						});
						uni.showToast({
							title: '登录过期,请重新登录',
							icon: 'none'
						});
					}
				}

			});

			uni.getSystemInfo({
				success: res => {
					// console.log(res);
					app.globalData.safeAreaBottom = res.safeAreaInsets.bottom;
				}
			});
			setTimeout(function() {
				// 初始化完成后再执行
				app.$core.get({
					url: 'fitness.common/init_config',
					data: {},
					loading: false,
					success: (ret) => {
						app.globalData.config = ret.data
					}
				})
			}, 1);
		},

		onShow: function(e) {
			if (e.query) {
				if (e.query.pid != 'undefined' && e.query.pid > 0) {
					let pid = e.query.pid;
					uni.setStorageSync('puser_id', pid);
				} else if (e.query.scene) {
					let scene = decodeURIComponent(e.query.scene);
					let options = {}
					for (var i = 0; i < scene.split('&').length; i++) {
						var arr = scene.split('&')[i].split('=');
						options[arr[0]] = arr[1];
					}
					if (options.pid != 'undefined' && options.pid > 0) {
						let pid = options.pid;
						uni.setStorageSync('puser_id', pid);
					}
				}

			}

		},
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	@import "common/demo.scss";

	.container {
		min-height: 100vh;
		background: linear-gradient(180deg, #FFFFFF 0%, #F6F6F6 100%);
	}
</style>